package com.jielihaofeng.level2;

import java.io.PrintWriter;
import java.io.StringWriter;

/**
 * @author Johnnie Wind
 * @description
 * @date 2021/11/30 14:03
 */
public class ThrowableTest {
    public static void main(String[] args) {
        Throwable th = new Throwable("Hello World");
        // 获取异常的message
        System.out.println(th.getMessage());
        // 获取异常的堆栈信息
        StringWriter stringWriter = new StringWriter();
        th.printStackTrace(new PrintWriter(stringWriter));
        String msg = stringWriter.toString();
        System.out.println(msg);
        // 重新填充堆栈的信息，输出控制台
        th.fillInStackTrace();
        th.printStackTrace(System.out);

    }
}
